home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
misc
/
emu
/
ATUtilities.lha
/
ATUtilities
/
atf.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-09-26
|
50KB
|
2,206 lines
/* ******************************************************************* */
/* ** ** */
/* ** ATUtilities Library ** */
/* ** Copright (C) 1992-1994 by Thomas Dreibholz ** */
/* ** All rights reserved ** */
/* ** ** */
/* ** Funktionen ** */
/* ** ** */
/* ******************************************************************* */
#include "janus.h"
#include "ATUtilities.h"
#define VERSION "ATUtilities Library - Version 4.0"
extern struct Library *IconBase;
extern struct Library *SysBase;
extern struct DosLibrary *DOSBase;
extern struct IntuitionBase *IntuitionBase;
extern struct GfxBase *GfxBase;
extern struct JanusBase *JanusBase;
extern struct Library *WorkbenchBase;
extern struct DiskfontBase *DiskfontBase;
extern struct TextFont *OpalFont;
struct Remember *Remember;
struct ATUtilities *atu;
VOID ErrorRequest();
VOID UseMenuStrip();
VOID LibraryInfo();
VOID FreeCommMemory();
VOID DrawIt();
VOID PrintText();
VOID SelectStdFPen();
VOID SelectStdBPen();
VOID InfoText();
VOID Utility();
VOID InformationBox();
VOID DrawMPTextBorder();
VOID MacFormat();
VOID RemoveMenuStrip();
UBYTE *GetOpalLine();
BOOL MultiRequest();
UBYTE *AllocCommMemory();
UWORD BorderHeight();
struct MenuItem *AddItem();
struct Menu *AddMenu();
struct MenuStrip *BuildMenuStrip();
struct CommManager
{
LONG UserCount;
UBYTE *CommMemory;
};
struct CommManager CommManager={0L,NULL};
struct TextAttr OpalAttr=
{
"opal.font",9,
FS_NORMAL,0
};
struct TextAttr TopazAttr=
{
"topaz.font",8,
FS_NORMAL,FPF_ROMFONT
};
struct IntuiText Warn_Text[]=
{
{2,0,JAM1,10,9,&OpalAttr,"Warnung: Das Beenden dieses ATUtilities",&Warn_Text[1]},
{2,0,JAM1,10,18,&OpalAttr,"kann Probleme verursachen, wenn MS-DOS",&Warn_Text[2]},
{2,0,JAM1,10,27,&OpalAttr,"einen erneuten Zugriffsversuch macht!",&Warn_Text[3]},
{2,0,JAM1,10,36,&OpalAttr,"Nach Beendigung sollte ein Reset der",&Warn_Text[4]},
{2,0,JAM1,10,45,&OpalAttr,"PC/AT-Karte gemacht werden.",&Warn_Text[5]},
{2,0,JAM1,10,54,&OpalAttr,"Wollen Sie wirklich beenden?",NULL}
};
struct IntuiText Beende_Text=
{
2,0,JAM1,10,8,&OpalAttr,"Ja, Programmende",NULL
};
struct IntuiText BeendeNicht_Text=
{
2,0,JAM1,10,8,&OpalAttr,"Nein, zurück",NULL
};
struct IntuiText Okay_Text=
{
2,0,JAM1,10,8,&OpalAttr,"Okay",NULL
};
UBYTE *Fehler[]=
{
{"Fehler beim Öffnen der Janus-Library."},
{"Fehler beim Öffnen der DiskFont-Library."},
{"Fehler beim Laden des Opal/9-Fonts."},
{"Fehler bei der Menü-Installation."},
{"Nicht genug freier Speicher."},
{"Nicht genug freie Task-Signale."},
{"Janus-Interrupt ist schon belegt!"},
{"Nicht genug freier DualPorted-Speicher."},
{"Kann Message-Port nicht erstellen."},
{"Kann Port für Utility-Manager nicht erstellen."},
{"Kann Service nicht erstellen."},
{"ATUtilities: Undefinierter Fehler."}
};
struct MenuItem StdItem=
{
NULL,
140,0,300,10,
HIGHCOMP|ITEMTEXT|ITEMENABLED,0L,
NULL,NULL,0,NULL,0
};
struct IntuiText StdReqText=
{
2,0,JAM1,10,8,&OpalAttr,NULL,NULL
};
struct IntuiText StdText=
{
AUTOFRONTPEN,AUTOBACKPEN,AUTODRAWMODE,AUTOLEFTEDGE,
1,&OpalAttr,NULL,NULL
};
struct NewWindow StdWindow=
{
0,0,0,0,
0,1,
0L,0L,
NULL,NULL,NULL,NULL,NULL,
50,20,640,256,
WBENCHSCREEN
};
struct Gadget StdGadget=
{
NULL,
0,0,0,0,
GADGHCOMP,
RELVERIFY|GADGIMMEDIATE,
BOOLGADGET,
NULL,NULL,NULL,0L,
NULL,0,NULL
};
struct Gadget StdStrGadget=
{
NULL,
0,0,0,0,
GADGHCOMP,
RELVERIFY|GADGIMMEDIATE|TOGGLESELECT,
STRGADGET,
NULL,NULL,NULL,0L,
NULL,0,NULL
};
/* Opal-Font öffnen */
struct TextFont *GetOpalFont()
{
return(OpalFont);
}
/* Warnung vorm Beenden von externen ATUtilities */
BOOL ExitWarning()
{
return(AutoRequest(NULL,&Warn_Text[0],&Beende_Text,&BeendeNicht_Text,
VANILLAKEY,0,450,88));
}
/* Abfrage zur Übernahme von Einstellungen */
BOOL UsePrefs()
{
return(MultiRequest("Wollen Sie die gemachten Einstellungen",
"übernehmen oder verwerfen ?",
"Übernehmen","Verwerfen"));
}
/* Fehler-Requester */
VOID ErrorRequest(num)
ULONG num;
{
struct IntuiText Text;
CopyMem(&StdReqText,&Text,sizeof(struct IntuiText));
if(num>ERRORCNT) num=ERRORCNT;
Text.IText=Fehler[num];
AutoRequest(NULL,&Text,&Okay_Text,&Okay_Text,VANILLAKEY,0,400,35);
}
/* Info-Requester */
VOID InfoRequest(info)
UBYTE *info;
{
struct IntuiText Text;
CopyMem(&StdReqText,&Text,sizeof(struct IntuiText));
Text.IText=info;
AutoRequest(NULL,&Text,&Okay_Text,&Okay_Text,VANILLAKEY,0,400,35);
}
/* Multi-Requester */
BOOL MultiRequest(t1,t2,p,n)
UBYTE *t1,*t2,*p,*n;
{
struct IntuiText Text1,Text2,TextP,TextN;
CopyMem(&StdReqText,&Text1,sizeof(struct IntuiText));
CopyMem(&StdReqText,&Text2,sizeof(struct IntuiText));
CopyMem(&StdReqText,&TextP,sizeof(struct IntuiText));
CopyMem(&StdReqText,&TextN,sizeof(struct IntuiText));
if(n==NULL) n=p;
Text1.IText=t1;
Text1.NextText=&Text2;
Text2.IText=t2;
Text2.TopEdge=18;
TextP.IText=p;
TextN.IText=n;
return(AutoRequest(NULL,&Text1,&TextP,&TextN,VANILLAKEY,0,450,45));
}
VOID CallUtility(name)
UBYTE *name;
{
Utility(name,UTILITY_CALL);
}
/* Utility-Fenster aufrufen */
VOID Utility(name,type)
UBYTE *name;
UWORD type;
{
register struct MsgPort *port;
register struct Message *msg;
port=FindPort(name);
if(port!=NULL)
{
msg=AllocMem(sizeof(struct Message),MEMF_CLEAR|MEMF_PUBLIC);
if(msg!=NULL)
{
msg->mn_Node.ln_Type=NT_MESSAGE;
msg->mn_Node.ln_Name=type;
msg->mn_Node.mn_Length=sizeof(struct Message);
PutMsg(port,msg);
}
else
{
ErrorRequest(ERROR_ALLOC);
}
}
else
{
MultiRequest("Externe Erweiterung ist (noch) nicht aktiv:",name,"Okay",NULL);
}
}
/* Utilityliste laden */
struct MenuItem *CreateUtilityList()
{
REGISTER BOOL err;
REGISTER WORD i,y;
register struct FileHandle *fh;
register struct MenuItem *item,*oldItem;
register struct IntuiText *text;
err=FALSE;
item=oldItem=NULL;
Remember=NULL;
atu=AllocRemember(Remember,sizeof(struct ATUtilities),MEMF_CLEAR|MEMF_PUBLIC);
if(atu!=NULL)
{
fh=Open("AT:Prefs/UtilityManager.prefs",MODE_OLDFILE);
if(fh!=NULL)
{
Read(fh,atu,sizeof(struct ATUtilities));
Close(fh);
y=4;
for(i=0;i<=atu->Count;i++)
{
oldItem=item;
item=AllocRemember(Remember,sizeof(struct MenuItem),MEMF_CLEAR|MEMF_PUBLIC);
text=AllocRemember(Remember,sizeof(struct IntuiText),MEMF_CLEAR|MEMF_PUBLIC);
if((item==NULL)||(text==NULL))
{
FreeRemember(Remember,TRUE);
return(NULL);
}
CopyMem(&StdItem,item,sizeof(struct MenuItem));
CopyMem(&StdText,text,sizeof(struct IntuiText));
item->NextItem=oldItem;
item->TopEdge=y;
item->ItemFill=text;
text->IText=&atu->ATUtility[i].Name;
y+=10;
}
}
else
{
FreeRemember(Remember,TRUE);
MultiRequest("Datei AT:Prefs/ATUtilityManager.prefs",
"konnte nicht geöffnet werden.","Okay",NULL);
}
}
return(item);
}
/* Utility-Liste entfernen */
VOID DeleteUtilityList()
{
if(Remember)
{
FreeRemember(Remember,TRUE);
Remember=NULL;
}
}
/* Utility aus Liste aufrufen */
VOID CallUtilityList(num)
ULONG num;
{
if(num<=atu->Count)
{
num=atu->Count-num;
if(num<atu->Count)
{
CallUtility(&atu->ATUtility[num].PortName);
}
else if(num==atu->Count) LibraryInfo();
}
}
/* JInterrupt-Handler erstellen */
struct ExtSetupSig *CreatePublicHandler(jint)
UBYTE jint;
{
REGISTER LONG JanusSignal;
REGISTER UBYTE *mem;
register struct ExtSetupSig *ess;
register struct SetupSig *ss;
ess=NULL;
Forbid();
if(JanusBase==NULL) JanusBase=OpenLibrary("janus.library",0L);
Permit();
if(JanusBase!=NULL)
{
JanusSignal=AllocSignal(-1L);
if(JanusSignal>=0)
{
mem=AllocCommMemory();
if(mem!=NULL)
{
ess=AllocMem(sizeof(struct ExtSetupSig),MEMF_CLEAR|MEMF_PUBLIC);
if(ess!=NULL)
{
ss=SetupJanusSig(jint,JanusSignal,0L,0L);
if(ss!=NULL)
{
ess->SetupSig=ss;
ess->ByteAccess=MakeBytePtr(mem);
ess->WordAccess=MakeWordPtr(mem);
ess->Offset=JanusMemToOffset(mem);
ess->JanusSignal=JanusSignal;
ess->JanusSignalMask=(1L<<JanusSignal);
SetParamOffset(jint,ess->Offset);
}
else
{
FreeMem(ess,sizeof(struct ExtSetupSig));
ess=NULL;
FreeSignal(JanusSignal);
FreeCommMemory();
ErrorRequest(ERROR_SETUP);
}
}
else
{
FreeSignal(JanusSignal);
FreeCommMemory();
ErrorRequest(ERROR_SETUP);
}
}
else
{
FreeSignal(JanusSignal);
ErrorRequest(ERROR_JALLOC);
}
}
else
{
ErrorRequest(ERROR_SIGNAL);
}
}
else
{
ErrorRequest(ERROR_JANUS);
}
return(ess);
}
/* JInterrupt-Handler löschen */
VOID DeletePublicHandler(ess)
struct ExtSetupSig *ess;
{
register struct SetupSig *ss;
ss=ess->SetupSig;
SetParamOffset(ss->ss_JanusIntNum,-1);
CleanupJanusSig(ss);
FreeSignal(ess->JanusSignal);
FreeCommMemory();
FreeMem(ess,sizeof(struct ExtSetupSig));
}
/* Kommunikationsspeicher belegen */
UBYTE *AllocCommMemory()
{
REGISTER UBYTE *mem;
Forbid();
if(CommManager.CommMemory!=NULL)
{
mem=CommManager.CommMemory;
CommManager.UserCount++;
}
else
{
mem=AllocJanusMem(sizeof(struct CommMemory),MEMF_BUFFER|MEM_WORDACCESS);
if(mem!=NULL)
{
CommManager.CommMemory=mem;
CommManager.UserCount=1;
}
}
Permit();
return(mem);
}
/* Kommunikationsspeicher freigeben */
VOID FreeCommMemory()
{
Forbid();
CommManager.UserCount--;
if(CommManager.UserCount==0)
{
FreeJanusMem(CommManager.CommMemory,sizeof(struct CommMemory));
CommManager.CommMemory=NULL;
}
Permit();
}
/* Gadget-Rahmen zeichnen (normal) */
VOID DrawPBorder(win,x,y,w,h,test)
struct Window *win;
UWORD x,y,w,h,test;
{
REGISTER BYTE f,b;
register struct RastPort *rp;
rp=win->RPort;
if(SysBase->lib_Version>=36) { f=2; b=1; } else { f=1; b=2; }
DrawIt(rp,x,y,w,h,f,b,test);
}
/* Gadget-Rahmen zeichnen (gedrückt) */
VOID DrawNBorder(win,x,y,w,h,test)
struct Window *win;
UWORD x,y,w,h,test;
{
REGISTER BYTE f,b;
register struct RastPort *rp;
rp=win->RPort;
if(SysBase->lib_Version>=36) { f=1; b=2; } else { f=2; b=1; }
DrawIt(rp,x,y,w,h,f,b,test);
}
/* Gadget-Rahmen mit Text zeichnen (normal) */
VOID DrawPTextBorder(win,x,y,w,h,text,test)
struct Window *win;
UWORD x,y,w,h;
UBYTE *text;
UWORD test;
{
REGISTER BYTE f,b;
register struct RastPort *rp;
rp=win->RPort;
if(SysBase->lib_Version>=36) { f=2; b=1; } else { f=1; b=2; }
DrawIt(rp,x,y,w,h,f,b,test);
SelectStdFPen(rp);
PrintText(rp,x,y,w,text);
}
/* Gadget-Rahmen mit Text zeichnen (gedrückt) */
VOID DrawNTextBorder(win,x,y,w,h,text,test)
struct Window *win;
UWORD x,y,w,h;
UBYTE *text;
UWORD test;
{
REGISTER BYTE f,b;
register struct RastPort *rp;
rp=win->RPort;
if(SysBase->lib_Version>=36) { f=1; b=2; } else { f=2; b=1; }
DrawIt(rp,x,y,w,h,f,b,test);
SelectStdFPen(rp);
PrintText(rp,x,y,w,text);
}
/* Gadget-Rahmen zeichnen (intern) */
VOID DrawIt(rp,x,y,w,h,f,b,fill)
struct RastPort *rp;
UWORD x,y,w,h;
UBYTE f,b;
UWORD fill;
{
if(fill==1)
{
SetAPen(rp,0);
RectFill(rp,x+1,y+2,x+w-2,y+h-2);
}
SetAPen(rp,f);
Move(rp,x,y+h);
Draw(rp,x,y);
Draw(rp,x+w,y);
SetAPen(rp,b);
Move(rp,x+1,y+h);
Draw(rp,x+w,y+h);
Draw(rp,x+w,y+1);
}
/* Gadget-Text zentrieren und ausgeben (intern) */
VOID PrintText(rp,x,y,w,text)
struct RastPort *rp;
UWORD x,y,w;
UBYTE *text;
{
REGISTER WORD i,l;
l=TextLength(rp,text,strlen(text));
i=(w-l)/2;
Move(rp,x+i,y+9);
Text(rp,text,strlen(text));
}
/* Text ausgeben */
VOID WriteText(rp,x,y,text)
struct RastPort *rp;
UWORD x,y;
UBYTE *text;
{
Move(rp,x,y);
Text(rp,text,strlen(text));
}
/* Text ausgeben und falls nötig entsprechend kürzen*/
VOID WriteMText(rp,x,y,width,text)
struct RastPort *rp;
UWORD x,y;
UWORD width;
UBYTE *text;
{
REGISTER UWORD i,j;
UBYTE s[204];
width-=20;
i=strlen(text);
j=TextLength(rp,text,i);
if(j>=width)
{
if(i>198) { i=198; s[199]=0x00; }
strncpy(&s,text,i);
MacFormat(rp,&s,width);
Move(rp,x,y);
Text(rp,&s,strlen(&s));
} else WriteText(rp,x,y,text);
}
/* Standard-Vordergrundfarbe */
VOID SelectStdFPen(rp)
struct RastPort *rp;
{
REGISTER UBYTE f;
if(SysBase->lib_Version>=36) f=2; else f=1;
SetAPen(rp,f);
}
/* Standard-Hintergrundfarbe */
VOID SelectStdBPen(rp)
struct RastPort *rp;
{
REGISTER UBYTE b;
if(SysBase->lib_Version>=36) b=1; else b=2;
SetAPen(rp,b);
}
/* Fenster öffnen */
struct Window *CreateWindow(scr,title,x,y,w,h,idcmp,flags)
struct Screen *scr;
UBYTE *title;
UWORD x,y,w,h;
ULONG flags,idcmp;
{
struct NewWindow *nw;
struct Window *win;
nw=AllocMem(sizeof(struct NewWindow),MEMF_CLEAR|MEMF_PUBLIC);
if(nw!=NULL)
{
CopyMem(&StdWindow,nw,sizeof(struct NewWindow));
nw->LeftEdge=x;
nw->TopEdge=y;
nw->Width=w;
nw->Height=h;
nw->IDCMPFlags=idcmp;
nw->Flags=flags;
nw->Title=title;
if(scr!=NULL)
{
nw->Screen=scr;
nw->Type=CUSTOMSCREEN;
nw->MaxWidth=scr->Width;
nw->MaxHeight=scr->Height;
}
win=OpenWindow(nw);
if(win!=NULL) win->UserData=NULL;
FreeMem(nw,sizeof(struct NewWindow));
return(win);
}
return(NULL);
}
/* Screen öffnen */
struct Screen *CreateScreen(title,w,h,d,vmodes)
UBYTE *title;
UWORD w,h;
UBYTE d;
ULONG vmodes;
{
struct NewScreen *ns;
struct Screen *scr;
ns=AllocMem(sizeof(struct NewScreen),MEMF_CLEAR|MEMF_PUBLIC);
if(ns!=NULL)
{
ns->Width=w;
ns->Height=h;
ns->Depth=d;
ns->Type=CUSTOMSCREEN;
ns->DefaultTitle=title;
ns->ViewModes=vmodes;
ns->BlockPen=1;
ns->Font=&TopazAttr;
scr=OpenScreen(ns);
FreeMem(ns,sizeof(struct NewScreen));
return(scr);
}
return(NULL);
}
/* Fenster entfernen */
VOID DeleteStdWindow(win)
struct Window *win;
{
REGISTER BOOL bool;
register struct Remember *rem;
bool=FALSE;
if(win->UserData)
{
rem=&win->UserData;
bool=TRUE;
}
CloseWindow(win);
if(bool) FreeRemember(rem,TRUE);
}
/* Bool- oder Toggle-Gadget erstellen */
struct Gadget *CreateBoolToggleGadget(test,win,x,y,w,h,text,id)
UWORD test;
struct Window *win;
UWORD x,y,w,h;
UBYTE *text;
UWORD id;
{
REGISTER UBYTE f,b;
UWORD size;
REGISTER WORD i,l;
BOOL toggle;
register struct RastPort *rp;
register struct Gadget *gad;
register struct IntuiText *it;
register struct Border *b1,*b2,*b3,*b4;
register struct TextAttr *ta;
UWORD *a1,*a2;
if((test==1)||(test==2))
{
toggle=TRUE;
size=sizeof(struct Gadget)+4*(sizeof(struct Border))+24+sizeof(struct IntuiText)+sizeof(struct TextAttr);
}
else
{
toggle=FALSE;
size=sizeof(struct Gadget);
}
gad=AllocRemember(&win->UserData,size,MEMF_CLEAR|MEMF_PUBLIC);
if(gad!=NULL)
{
CopyMem(&StdGadget,gad,sizeof(struct Gadget));
if(toggle==TRUE)
{
rp=win->RPort;
if(SysBase->lib_Version>=36) { f=2; b=1; } else { f=1; b=2; }
gad->Activation |= TOGGLESELECT;
gad->Flags=GADGHIMAGE;
if(test==2) gad->Flags |= SELECTED;
b1=(ULONG)gad+(ULONG)sizeof(struct Gadget);
b2=(ULONG)b1+(ULONG)sizeof(struct Border);
b3=(ULONG)b2+(ULONG)sizeof(struct Border);
b4=(ULONG)b3+(ULONG)sizeof(struct Border);
a1=(ULONG)b4+(ULONG)sizeof(struct Border);
a2=(ULONG)a1+12L;
it=(ULONG)a2+12L;
ta=(ULONG)it+(ULONG)sizeof(struct IntuiText);
b1->LeftEdge=0;
b1->TopEdge=0;
b1->DrawMode=JAM1;
b1->Count=3;
CopyMem(b1,b2,sizeof(struct Border));
b1->FrontPen=f;
b1->BackPen=b;
b1->XY=a1;
b2->FrontPen=b;
b2->BackPen=f;
b2->XY=a2;
CopyMem(b1,b3,sizeof(struct Border));
CopyMem(b2,b4,sizeof(struct Border));
b3->FrontPen=b;
b3->BackPen=f;
b4->FrontPen=f;
b4->BackPen=b;
b1->NextBorder=b2;
b3->NextBorder=b4;
a1[0]=0; a1[1]=h; a1[2]=0; a1[3]=0; a1[4]=w; a1[5]=0;
a2[0]=1; a2[1]=h; a2[2]=w; a2[3]=h; a2[4]=w; a2[5]=1;
gad->GadgetRender=b1;
gad->SelectRender=b3;
it->FrontPen=f;
it->BackPen=b;
it->DrawMode=JAM1;
l=TextLength(rp,text,strlen(text));
i=(w-l)/2;
it->LeftEdge=i;
it->TopEdge=2;
it->ITextFont=ta;
it->IText=text;
gad->GadgetText=it;
ta->ta_Name=rp->Font->tf_Message.mn_Node.ln_Name;
ta->ta_YSize=rp->Font->tf_YSize;
ta->ta_Flags=rp->Font->tf_Flags;
ta->ta_Style=rp->AlgoStyle;
}
if(test==4) gad->Flags=GADGHNONE;
gad->LeftEdge=x;
gad->TopEdge=y;
gad->Width=w+1;
gad->Height=h+1;
gad->GadgetID=id;
AddGadget(win,gad,NULL);
OnGadget(gad,win,NULL);
if(test==0) DrawPTextBorder(win,x,y,w,h,text);
if(test==5) DrawMPTextBorder(win,x,y,w,h,text);
}
return(gad);
}
/* String- oder Integer-Gadget erstellen */
UBYTE *CreateStrIntGadget(test,win,x,y,w,h,str,maxPos,id)
UWORD test;
struct Window *win;
UWORD x,y,w,h;
UBYTE *str;
UWORD maxPos,id;
{
REGISTER LONG i;
REGISTER UBYTE *buffer,*undo;
register struct Gadget *gad;
register struct StringInfo *si;
buffer=NULL;
i=sizeof(struct Gadget)+sizeof(struct StringInfo)+(maxPos*2);
gad=AllocRemember(&win->UserData,i,MEMF_CLEAR|MEMF_PUBLIC);
if(gad!=NULL)
{
si=(ULONG)gad+(ULONG)sizeof(struct Gadget);
buffer=(ULONG)si+(ULONG)sizeof(struct StringInfo);
undo=(ULONG)buffer+(ULONG)maxPos;
CopyMem(&StdStrGadget,gad,sizeof(struct Gadget));
if(test==1) gad->Activation += LONGINT;
si->Buffer=buffer;
si->UndoBuffer=undo;
si->MaxChars=maxPos;
if(str!=NULL) si->BufferPos=strlen(str);
strcpy(buffer,str);
if(h<=10)
{
gad->LeftEdge=x+3;
gad->Width=w-3;
}
else
{
gad->LeftEdge=x+4;
gad->Width=w-5;
}
gad->TopEdge=y+2;
gad->Height=h;
gad->GadgetID=id;
gad->SpecialInfo=si;
AddGadget(win,gad,NULL);
OnGadget(gad,win,NULL);
if(h<=10)
{
DrawNBorder(win,x,y,w,h);
}
else
{
DrawNBorder(win,x+1,y+1,w-2,h-2);
DrawPBorder(win,x,y,w,h);
}
}
return(buffer);
}
/* Parallelen Prozeß erstellen */
struct Task *CreateProcess(function,stack,name,pri)
VOID (* function)();
ULONG stack;
UBYTE *name;
BYTE pri;
{
register struct Process *proc;
register struct Segment *Segment;
/* ----- Segment installieren ----------------------------------------- */
Segment=AllocMem(sizeof(struct Segment),MEMF_CLEAR|MEMF_PUBLIC);
if(Segment==NULL) return(NULL);
Segment->Length=sizeof(struct Segment);
Segment->Next=NULL;
Segment->OpCode=0x4EF9; /* JMP */
Segment->Address=function;
Segment=(LONG)(&(Segment->Next)) >> 2;
/* ----- Prozeß starten ----------------------------------------------- */
proc=CreateProc(name,pri,Segment,stack);
if(proc==NULL) return(NULL);
/* ----- Weitere Installationen --------------------------------------- */
return((struct Task *)((ULONG)proc-(ULONG)sizeof(struct Task)));
}
/* Anzahl der freien Bytes von Janus-Speicher ermitteln */
LONG AvailJanusMem(type)
UWORD type;
{
REGISTER LONG bytes;
register struct DualPortedMemory *dpm;
bytes=0;
Forbid();
JanusBase=OpenLibrary("janus.library",0L);
Permit();
if(JanusBase!=NULL)
{
dpm=MakeWordPtr(JanusBase->ParameterRAM);
if(type & MEMF_PARAMETER) bytes=dpm->ParameterRAM.Free;
if(type & MEMF_BUFFER) bytes+=dpm->BufferRAM.Free;
}
return(bytes);
}
/* Message beantworten */
UWORD Received(port)
struct MsgPort *port;
{
REGISTER UWORD res;
register struct Message *msg;
msg=GetMsg(port);
if(msg!=NULL)
{
res=msg->mn_Node.ln_Name;
FreeMem(msg,sizeof(struct Message));
}
else res=0;
return(res);
}
/* Informationen zum Programm */
VOID InformationBox(scr,title,cp1,cp2,cp3,cp4,iconName,info)
struct Screen *scr;
UBYTE *title;
UBYTE *cp1,*cp2,*cp3,*cp4;
UBYTE *iconName;
struct Info *info;
{
UBYTE TextBuffer[56],fk,ok;
BOOL ende,new;
ULONG a,b,c;
UWORD i,j;
REGISTER UBYTE *Prozessor;
REGISTER UBYTE *Coprozessor;
REGISTER UBYTE *Cache;
register struct RastPort *InfoRastPort;
register struct IntuiMessage *IMessage;
register struct Gadget *gad;
register struct DualPortedMemory *dpm;
register struct Window *InfoWindow;
register struct MenuStrip *ms;
register struct DiskObject *icon;
struct Image Image;
struct Image *im;
icon=NULL;
if(IconBase && iconName) icon=GetDiskObject(iconName);
Forbid();
if(JanusBase==NULL) JanusBase=OpenLibrary("janus.library",0L);
Permit();
if(!(strncmp(cp1,"$VER: ",6))) cp1=(ULONG)cp1+(ULONG)6;
InfoWindow=CreateWindow(scr,title,75,35,450,155+BorderHeight(),
CLOSEWINDOW|INACTIVEWINDOW|VANILLAKEY|MENUPICK,
ACTIVATE|WINDOWCLOSE|WINDOWDEPTH|WINDOWDRAG|GIMMEZEROZERO);
if(InfoWindow!=NULL)
{
InfoRastPort=InfoWindow->RPort;
SetFont(InfoRastPort,OpalFont);
ms=NULL;
if(info!=NULL)
{
ms=BuildMenuStrip(InfoWindow,AUTOFRONTPEN,AUTOBACKPEN);
if(ms!=NULL)
{
AddMenu(ms,"Information",5,200);
AddItem(ms,"Copyright und Systeminfos",300,'Z',TRUE,TRUE);
j=65;
for(a=0;a<info->Items;a++)
{
if(info->InfoItem[a]->ShowItem!=0)
{
AddItem(ms,info->InfoItem[a]->Title,300,j,info->InfoItem[a]->EnableItem,TRUE);
j++; if(j==(UWORD)'Q') j++; if(j==(UWORD)'Z') j=48;
}
else
AddItem(ms,GetOpalLine(),300,0,FALSE,FALSE);
}
AddItem(ms,GetOpalLine(),300,0,FALSE,FALSE);
AddItem(ms,"Information beenden",300,'Q',TRUE,TRUE);
UseMenuStrip(ms);
}
}
fk=ok=100;
new=TRUE;
ende=FALSE;
do
{
if(new==TRUE)
{
SetAPen(InfoRastPort,0);
RectFill(InfoRastPort,5,3,445,140);
if(fk==100)
{
if(JanusBase)
{
dpm=JanusBase->ParameterRAM;
dpm=MakeWordPtr(dpm);
a=dpm->ParameterRAM.Free/1024;
b=dpm->BufferRAM.Free/1024;
}
else
{
a=b=0;
}
Prozessor="Motorola 68000 16/32-Bit";
Coprozessor="Nicht installiert";
Cache="Nicht vorhanden";
if(SysBase->AttnFlags & AFF_68010)
Prozessor="Motorola 68010 16/32-Bit";
if(SysBase->AttnFlags & AFF_68020)
Prozessor="Motorola 68020 32-Bit";
if(SysBase->AttnFlags & AFF_68030)
{
Prozessor="Motorola 68030 32-Bit";
if(SysBase->lib_Version>=36)
{
c=CacheControl(0,0);
Cache="Ausgeschaltet";
if(c & CACRF_EnableD) Cache="Eingeschaltet";
if((c & CACRF_EnableD)&&(c & CACRF_DBE)) Cache="Burst-Modus";
}
else
{
Cache="(Test erst ab DOS 2.0)";
}
}
if(SysBase->AttnFlags & AFF_68881) Coprozessor="Motorola 68881";
if(SysBase->AttnFlags & AFF_68882) Coprozessor="Motorola 68882";
SetAPen(InfoRastPort,1);
if(icon)
{
gad=&icon->do_Gadget;
if(SysBase->lib_Version>=36)
{
DrawNBorder(InfoWindow,(417-gad->Width),25,gad->Width+6,gad->Height+6);
DrawPBorder(InfoWindow,27,25,gad->Width+6,gad->Height+6);
}
Image.LeftEdge=0;
Image.TopEdge=0;
Image.NextImage=NULL;
im=gad->GadgetRender;
Image.Width=im->Width;
Image.Height=im->Height;
Image.Depth=im->Depth;
Image.PlanePick=im->PlanePick;
Image.PlaneOnOff=im->PlaneOnOff;
Image.ImageData=im->ImageData;
DrawImage(InfoRastPort,&Image,30,28);
i=gad->SelectRender;
if(i!=NULL)
{
Image.Width=im->Width;
Image.Height=im->Height;
Image.Depth=im->Depth;
Image.PlanePick=im->PlanePick;
Image.PlaneOnOff=im->PlaneOnOff;
Image.ImageData=im->ImageData;
}
DrawImage(InfoRastPort,&Image,(420-gad->Width),28);
}
InfoText(InfoRastPort,cp1,10);
InfoText(InfoRastPort,cp2,20);
InfoText(InfoRastPort,cp3,30);
InfoText(InfoRastPort,cp4,40);
sprintf(&TextBuffer,"Parameter-Speicher: %2ld KB",a);
InfoText(InfoRastPort,&TextBuffer,55);
sprintf(&TextBuffer,"Buffer-Speicher: %2ld KB",b);
InfoText(InfoRastPort,&TextBuffer,65);
sprintf(&TextBuffer,"Chip-Speicher: %4ld KB",
(AvailMem(MEMF_CHIP))/1024);
InfoText(InfoRastPort,&TextBuffer,80);
sprintf(&TextBuffer,"Fast-Speicher: %4ld KB",
(AvailMem(MEMF_FAST))/1024);
InfoText(InfoRastPort,&TextBuffer,90);
sprintf(&TextBuffer,"Speicher gesamt: %5ld KB",
(AvailMem(MEMF_ANY))/1024);
InfoText(InfoRastPort,&TextBuffer,100);
sprintf(&TextBuffer,"Hauptprozessor: %s",Prozessor);
InfoText(InfoRastPort,&TextBuffer,115);
sprintf(&TextBuffer,"Math. Copozessor: %s",Coprozessor);
InfoText(InfoRastPort,&TextBuffer,125);
sprintf(&TextBuffer,"Datencache: %s",Cache);
InfoText(InfoRastPort,&TextBuffer,135);
}
else
{
j=10;
SetAPen(InfoRastPort,1);
for(i=0;i<14;i++)
{
if(info->InfoItem[fk]->Strings[i]!=0)
{
InfoText(InfoRastPort,info->InfoItem[fk]->Strings[i],j);
}
j+=10;
}
}
new=FALSE;
}
WaitPort(InfoWindow->UserPort);
IMessage=GetMsg(InfoWindow->UserPort);
a=IMessage->Class;
j=IMessage->Code;
ReplyMsg(IMessage);
switch(a)
{
case CLOSEWINDOW:
case VANILLAKEY:
case INACTIVEWINDOW:
ende=TRUE;
break;
case MENUPICK:
if(MENUNUM(j)==0)
{
i=ITEMNUM(j);
if(i==0)
ende=TRUE;
else
{
if((i>1)&&(i<=info->Items+1))
fk=(info->Items+1)-i;
else if(i>info->Items+1)
fk=100;
}
if(fk!=ok)
{
ok=fk;
new=TRUE;
}
}
break;
}
} while(ende==FALSE);
if(ms) RemoveMenuStrip(ms);
DeleteStdWindow(InfoWindow);
}
if(icon) FreeDiskObject(icon);
}
/* Text im Info-Fenster zentriert ausgeben */
VOID InfoText(rp,text,y)
struct RastPort *rp;
UBYTE *text;
WORD y;
{
REGISTER WORD x,length;
length=strlen(text);
x=(450-TextLength(rp,text,length))/2;
Move(rp,x,y);
Text(rp,text,length);
}
/* Cache-Steuerung bei Systemen mit 68020/030 und Kickstart 2.0 */
#asm
; Implementation von CacheControl
; (ab Kickstart 2.0)
public _CacheControl
_CacheControl:
move.l 4(sp),d0
move.l 8(sp),d1
move.l a6,-(sp)
move.l $4,a6
jsr -648(a6)
move.l (sp)+,a6
rts
#endasm
/* Information */
VOID LibraryInfo()
{
InformationBox(NULL,
"ATUtilities Library - Information",
VERSION,
"Copyright (C) 1992-1994 by",
"Thomas Dreibholz",
"All rights reserved",
"AT:Icons/Library",NULL);
}
/* JInterrupt-Handler erstellen */
struct ExtSetupSig *CreatePrivateHandler(jint,size)
UBYTE jint;
UWORD size;
{
REGISTER LONG JanusSignal;
REGISTER UWORD offset;
REGISTER UBYTE *mem;
register struct ExtSetupSig *ess;
register struct SetupSig *ss;
ess=NULL;
Forbid();
if(JanusBase==NULL) JanusBase=OpenLibrary("janus.library",0L);
Permit();
if(JanusBase!=NULL)
{
JanusSignal=AllocSignal(-1L);
if(JanusSignal>=0)
{
ess=AllocMem(sizeof(struct ExtSetupSig),MEMF_CLEAR|MEMF_PUBLIC);
if(ess!=NULL)
{
ss=SetupJanusSig(jint,JanusSignal,0,0);
if(ss!=NULL)
{
mem=AllocJanusMem(size+16,MEMF_BUFFER);
if(mem!=NULL)
{
ess->System1=mem;
ess->System2=size+16;
offset=JanusMemToOffset(mem);
offset=offset+(offset % 16);
mem=JanusOffsetToMem(offset,MEMF_BUFFER|MEM_BYTEACCESS);
ess->SetupSig=ss;
ess->ByteAccess=MakeBytePtr(mem);
ess->WordAccess=MakeWordPtr(mem);
ess->Offset=offset;
ess->JanusSignal=JanusSignal;
ess->JanusSignalMask=(1L<<JanusSignal);
SetParamOffset(jint,offset);
}
else
{
CleanupJanusSig(ss);
FreeMem(ess,sizeof(struct ExtSetupSig));
FreeSignal(JanusSignal);
ErrorRequest(ERROR_SETUP);
}
}
else
{
FreeMem(ess,sizeof(struct ExtSetupSig));
ess=NULL;
FreeSignal(JanusSignal);
ErrorRequest(ERROR_SETUP);
}
}
else
{
FreeSignal(JanusSignal);
ErrorRequest(ERROR_JALLOC);
}
}
else
{
ErrorRequest(ERROR_SIGNAL);
}
}
else
{
ErrorRequest(ERROR_JANUS);
}
return(ess);
}
/* JInterrupt-Handler löschen */
VOID DeletePrivateHandler(ess)
struct ExtSetupSig *ess;
{
CleanupJanusSig(ess->SetupSig);
FreeSignal(ess->JanusSignal);
FreeJanusMem(ess->System1,ess->System2);
FreeMem(ess,sizeof(struct ExtSetupSig));
}
/* DateStamp in normales Format umwandeln */
ULONG TageProMonat[]={00,31,28,31,
30,31,30,31,
31,30,31,30,
31};
VOID ConvertDateStamp(ds,new)
struct DateStamp *ds;
struct NewDateStamp *new;
{
REGISTER UWORD Tage,Jahr,Monat;
Tage=ds->ds_Days;
new->Hour=ds->ds_Minute/60;
new->Minute=ds->ds_Minute%60;
new->Second=ds->ds_Tick/TICKS_PER_SECOND;
new->DayNum=Tage%7;
Jahr=1978;
while(Tage>365)
{
if((Jahr%4)==0) Tage-=366; else Tage-=365;
Jahr++;
}
if((Tage==365) && !((Jahr%4)==0)) Tage-=365;
if((Jahr%4)==0) TageProMonat[2]=29; else TageProMonat[2]=28;
Monat=1;
while(Tage>=TageProMonat[Monat])
{
Tage-=TageProMonat[Monat];
Monat++;
}
Tage++;
new->Year=Jahr;
new->Month=Monat;
new->Day=Tage;
}
/* App-Item erstellen */
struct AppManager *CreateAppItem(text)
UBYTE *text;
{
struct AppManager *app;
struct MsgPort *port;
if(WorkbenchBase==NULL) return(NULL);
app=AllocMem(sizeof(struct AppManager),MEMF_CLEAR|MEMF_PUBLIC);
if(app!=NULL)
{
port=CreatePort(0L,0L);
if(port!=NULL)
{
app->Port=port;
app->AppItem=AddAppMenuItemA(0,0L,text,port,NULL);
app->SignalMask=(1L<<port->mp_SigBit);
if(app->AppItem==NULL)
{
DeletePort(port);
FreeMem(app,sizeof(struct AppManager));
return(NULL);
}
}
else
{
FreeMem(app,sizeof(struct AppManager));
return(NULL);
}
}
else return(NULL);
return(app);
}
/* App-Item löschen */
VOID DeleteAppItem(app)
struct AppManager *app;
{
RemoveAppMenuItem(app->AppItem);
DeletePort(app->Port);
FreeMem(app,sizeof(struct AppManager));
}
/* Task-Priorität ändern */
UBYTE ChangeTaskPri(pri)
UBYTE pri;
{
register struct Task *task;
task=FindTask(NULL);
return((UBYTE)SetTaskPri(task,pri));
}
/* Service erstellen */
struct ExtServiceData *CreatePublicService(appID,locID,flags)
ULONG appID;
UWORD locID;
UWORD flags;
{
LONG signal;
WORD okay;
UBYTE *mem;
UWORD *jmem;
struct ExtServiceData *esd;
struct ServiceData *serv;
Forbid();
if(JanusBase==NULL) JanusBase=OpenLibrary("janus.library",0L);
Permit();
if(JanusBase!=NULL)
{
mem=AllocCommMemory();
if(mem==NULL)
{
ErrorRequest(ERROR_JALLOC);
return(NULL);
}
esd=AllocMem(sizeof(struct ExtServiceData),MEMF_CLEAR|MEMF_PUBLIC);
if(esd==NULL)
{
ErrorRequest(ERROR_ALLOC);
FreeCommMemory();
return(NULL);
}
signal=AllocSignal(-1);
if(signal==-1)
{
ErrorRequest(ERROR_SIGNAL);
FreeCommMemory();
FreeMem(esd,sizeof(struct ExtServiceData));
return(NULL);
}
okay=AddService(&serv,appID,locID,16,MEMF_BUFFER|MEM_WORDACCESS,signal,flags);
if(okay==JSERV_OK)
{
esd->ServiceData=serv;
esd->ByteAccess=MakeBytePtr(mem);
esd->WordAccess=MakeWordPtr(mem);
esd->Offset=JanusMemToOffset(mem);
esd->JanusSignal=signal;
esd->JanusSignalMask=(1L<<signal);
esd->ServiceMem=serv->AmigaMemPtr;
/* Das Offset des Service-Speichers wird gegen das Offset des
CommMemory ausgetauscht - das Segment bleibt gleich wg. MEMF_BUFFER */
esd->System=serv->PCMemPtr.PCOffset;
serv->PCMemPtr.PCOffset=esd->Offset;
}
else
{
ErrorRequest(ERROR_ADDSERVICE);
FreeCommMemory();
FreeMem(esd,sizeof(struct ExtServiceData));
FreeSignal(signal);
return(NULL);
}
return(esd);
}
else
{
ErrorRequest(ERROR_JANUS);
return(NULL);
}
}
/* Service entfernen */
VOID DeletePublicService(esd)
struct ExtServiceData *esd;
{
esd->ServiceData->PCMemPtr.PCOffset=esd->System;
DeleteService(esd->ServiceData);
FreeSignal(esd->JanusSignal);
FreeCommMemory();
FreeMem(esd,sizeof(struct ExtServiceData));
}
/* Utility-Fenster aufrufen, ohne Requester bei Fehlern */
BOOL UtilityQuiet(name,type)
UBYTE *name;
UWORD type;
{
register struct MsgPort *port;
register struct Message *msg;
port=FindPort(name);
if(port!=NULL)
{
msg=AllocMem(sizeof(struct Message),MEMF_CLEAR|MEMF_PUBLIC);
if(msg!=NULL)
{
msg->mn_Node.ln_Type=NT_MESSAGE;
msg->mn_Node.ln_Name=type;
msg->mn_Node.mn_Length=sizeof(struct Message);
PutMsg(port,msg);
return(TRUE);
}
}
return(FALSE);
}
/* Text in hervorgehobenen Rahmen "Mac-like" ausgeben */
VOID DrawMPTextBorder(win,x,y,w,h,tex)
struct Window *win;
UWORD x,y,w,h;
UBYTE *tex;
{
REGISTER UWORD l;
UBYTE s[262];
if(w<25) w=25;
l=strlen(tex);
if(l>256) l=256;
strncpy(&s,tex,l+1);
MacFormat(win->RPort,&s,w-20);
DrawPTextBorder(win,x,y,w,h,&s,1);
}
/* Text in gedrückten Rahmen "Mac-like" ausgeben */
VOID DrawMNTextBorder(win,x,y,w,h,tex)
struct Window *win;
UWORD x,y,w,h;
UBYTE *tex;
{
REGISTER UWORD l;
UBYTE s[262];
if(w<25) w=25;
l=strlen(tex);
if(l>256) l=256;
strncpy(&s,tex,l+1);
MacFormat(win->RPort,&s,w-20);
DrawNTextBorder(win,x,y,w,h,&s,1);
}
/* Proportionalgadget erstellen */
struct Gadget *CreatePropGadget(win,x,y,w,h,hp,vp,hb,vb,id)
struct Window *win;
UWORD x,y,w,h;
UWORD hb,vb,hp,vp;
UWORD id;
{
register struct Gadget *gad;
register struct PropInfo *pi;
register struct Image *im;
gad=AllocRemember(&win->UserData,sizeof(struct Gadget)+
sizeof(struct PropInfo)+
sizeof(struct Image),MEMF_CLEAR|MEMF_PUBLIC);
if(gad!=NULL)
{
pi=(ULONG)gad+(ULONG)sizeof(struct Gadget);
im=(ULONG)pi+(ULONG)sizeof(struct PropInfo);
gad->LeftEdge=x+1;
gad->TopEdge=y+1;
gad->Width=w-1;
gad->Height=h-1;
gad->Flags=GADGHCOMP;
gad->Activation=RELVERIFY|GADGIMMEDIATE|FOLLOWMOUSE;
gad->GadgetType=PROPGADGET;
gad->GadgetRender=im;
gad->GadgetID=id;
gad->SpecialInfo=pi;
pi->Flags=PROPBORDERLESS|AUTOKNOB;
pi->HorizBody=hb;
pi->VertBody=vb;
pi->VertPot=vp;
pi->HorizPot=hp;
if(hb!=0) pi->Flags |= FREEHORIZ;
if(vb!=0) pi->Flags |= FREEVERT;
AddGadget(win,gad,-1);
OnGadget(gad,win,NULL);
DrawNBorder(win,x,y,w,h);
return(gad);
}
return(NULL);
}
/* MenuStrip Grundstruktur erstellen */
struct MenuStrip *BuildMenuStrip(win,fp,bp)
struct Window *win;
UWORD fp,bp;
{
register struct MenuStrip *ms;
register struct RastPort *rp;
ms=AllocMem(sizeof(struct MenuStrip),MEMF_CLEAR|MEMF_PUBLIC);
if(ms!=NULL)
{
ms->Window=win;
rp=win->RPort;
ms->TextAttr.ta_Name=rp->Font->tf_Message.mn_Node.ln_Name;
ms->TextAttr.ta_YSize=rp->Font->tf_YSize;
ms->TextAttr.ta_Flags=rp->Font->tf_Flags;
ms->TextAttr.ta_Style=rp->AlgoStyle;
ms->FrontPen=fp;
ms->BackPen=bp;
}
return(ms);
}
/* Neues Menü erstellen */
struct Menu *AddMenu(ms,name,x,w)
struct MenuStrip *ms;
UBYTE *name;
UWORD x,w;
{
register struct Menu *me;
me=AllocRemember(&ms->Remember,sizeof(struct Menu),MEMF_CLEAR|MEMF_PUBLIC);
if(me!=NULL)
{
me->LeftEdge=x;
me->TopEdge=0;
me->Width=w;
me->Height=10;
me->Flags=MENUENABLED;
me->MenuName=name;
me->NextMenu=ms->LastMenu;
ms->LastMenu=me;
ms->LastItem=NULL;
ms->LastSubItem=NULL;
}
return(me);
}
/* Neues Item erstellen */
struct MenuItem *AddItem(ms,name,w,cmd,enabled,highcomp)
struct MenuStrip *ms;
UBYTE *name;
UWORD w;
UBYTE cmd;
BOOL enabled,highcomp;
{
register struct Menu *me;
register struct MenuItem *mi;
register struct IntuiText *it;
me=ms->LastMenu;
if(me!=NULL)
{
mi=AllocRemember(&ms->Remember,sizeof(struct MenuItem)+sizeof(struct IntuiText),MEMF_CLEAR|MEMF_PUBLIC);
if(mi!=NULL)
{
it=(ULONG)mi+(ULONG)sizeof(struct MenuItem);
if(ms->LastItem!=NULL)
mi->TopEdge=ms->LastItem->TopEdge+10;
else
mi->TopEdge=0;
mi->LeftEdge=0;
mi->Width=w;
mi->Height=10;
mi->Flags=ITEMTEXT;
if(enabled) mi->Flags |= ITEMENABLED;
if(highcomp) mi->Flags |= HIGHCOMP; else mi->Flags |= HIGHNONE;
if(cmd!=0)
{
mi->Flags |= COMMSEQ;
mi->Command=cmd;
}
mi->ItemFill=it;
it->LeftEdge=AUTOLEFTEDGE;
it->TopEdge=1;
it->DrawMode=JAM1;
it->FrontPen=ms->FrontPen;
it->BackPen=ms->BackPen;
it->ITextFont=&ms->TextAttr;
it->IText=name;
mi->NextItem=ms->LastItem;
ms->LastItem=mi;
ms->LastSubItem=NULL;
me->FirstItem=mi;
}
}
return(mi);
}
/* Neues Sub-Item erstellen */
struct MenuItem *AddSubItem(ms,name,w,cmd,enabled,highcomp)
struct MenuStrip *ms;
UBYTE *name;
UWORD w;
UBYTE cmd;
BOOL enabled,highcomp;
{
register struct MenuItem *mi,*sub;
register struct IntuiText *it;
sub=ms->LastItem;
if(sub!=NULL)
{
mi=AllocRemember(&ms->Remember,sizeof(struct MenuItem)+sizeof(struct IntuiText),MEMF_CLEAR|MEMF_PUBLIC);
if(mi!=NULL)
{
it=(ULONG)mi+(ULONG)sizeof(struct MenuItem);
if(ms->LastItem!=NULL)
mi->TopEdge=ms->LastItem->TopEdge+10;
else
mi->TopEdge=0;
mi->LeftEdge=0;
mi->Width=w;
mi->Height=10;
mi->Flags=ITEMTEXT;
if(enabled) mi->Flags |= ITEMENABLED;
if(highcomp) mi->Flags |= HIGHCOMP; else mi->Flags |= HIGHNONE;
if(cmd!=0)
{
mi->Flags |= COMMSEQ;
mi->Command=cmd;
}
mi->ItemFill=it;
it->LeftEdge=AUTOLEFTEDGE;
it->TopEdge=1;
it->DrawMode=JAM1;
it->FrontPen=ms->FrontPen;
it->BackPen=ms->BackPen;
it->ITextFont=&ms->TextAttr;
it->IText=name;
mi->NextItem=ms->LastSubItem;
ms->LastSubItem=mi;
sub->SubItem=mi;
}
}
return(mi);
}
/* Menü-Strip zu Window hinzufügen */
VOID UseMenuStrip(ms)
struct MenuStrip *ms;
{
if(ms->LastMenu!=NULL) SetMenuStrip(ms->Window,ms->LastMenu);
}
/* Menü-Strip entfernen */
VOID RemoveMenuStrip(ms,bool)
struct MenuStrip *ms;
BOOL bool;
{
ClearMenuStrip(ms->Window);
if(ms->Remember!=NULL) FreeRemember(&ms->Remember,TRUE);
ms->Remember=NULL;
ms->LastMenu=NULL;
ms->LastItem=NULL;
ms->LastSubItem=NULL;
if(bool==TRUE) FreeMem(ms,sizeof(struct MenuStrip));
}
/* 300 Pixel-Trennlinie für Opal-Font */
UBYTE *GetOpalLine()
{
return((UBYTE *)"·········································································");
}
/* 450 Pixel-Trennlinie für Opal-Font */
UBYTE *GetOpalLine450()
{
return((UBYTE *)"···············································································································");
}
/* String in Mac-like-Format umwandeln */
VOID MacFormat(rp,tex,x)
struct RastPort *rp;
UBYTE *tex;
UWORD x;
{
REGISTER UWORD i,j,k,l;
k=strlen(tex);
l=TextLength(rp,tex,k);
if(l>x)
{
i=0;
j=TextLength(rp,"...",3);
l=j;
do
{
j+=TextLength(rp,&tex[i],1L);
i++;
} while(j<x);
tex[i]=0x00;
for(j=i-1;j>0;j--)
{
if(tex[j]==' ') tex[j]=0x00; else break;
}
if(tex[0]!=0x00) strcat(tex,"...");
}
}
struct BMHD
{
UWORD Width,Height;
UWORD LeftEdge,TopEdge;
UBYTE BitPlanes;
UBYTE Masking;
UBYTE Compression;
UBYTE pad;
UWORD TransCol;
UBYTE XAspace,YAspect;
UWORD ScreenWidth,ScreenHeight;
};
struct ColReg
{
UBYTE Red;
UBYTE Green;
UBYTE Blue;
};
struct CAMG
{
UWORD pad;
UWORD ViewModes;
};
struct CRNG
{
UWORD pad;
UWORD Rate;
UWORD Active;
UBYTE Low,High;
};
struct RInfo
{
UBYTE *Memory;
ULONG Pos;
ULONG Max;
};
ULONG Lesen(ri,m,l)
struct RInfo *ri;
UBYTE *m;
ULONG l;
{
if((ri->Pos+l)>ri->Max) l=(ri->Max-ri->Pos);
CopyMem(&ri->Memory[ri->Pos],m,l);
ri->Pos+=l;
return(l);
}
VOID Jump(ri,l)
struct RInfo *ri;
ULONG l;
{
if((ri->Pos+l)>ri->Max) l=(ri->Max-ri->Pos);
ri->Pos+=l;
}
UBYTE ColorCount[]={1,2,4,8,16,32,32,32,32};
/* ILBM-Bild anzeigen */
BOOL DisplayPicture(mem,len)
UBYTE *mem;
LONG len;
{
struct Screen *scr;
struct NewScreen ns;
UBYTE Buffer[300];
ULONG l;
BOOL BMHDFlag,BODYFlag,CMAPFlag,CAMGFlag,CRNGFlag,FoundChunk;
ULONG ChunkLen;
UWORD y,ByteCount,i;
UWORD iRowBytes,scrRowBytes;
UWORD scrWidth,scrHeight,iWidth,iHeight;
UBYTE iDepth,b;
ULONG dest;
struct RInfo *fh;
struct RInfo ri;
struct BMHD bmhd;
struct CAMG camg;
struct CRNG crng;
struct ColReg Farben[32];
UWORD AnzFarben;
struct ColReg Farbe;
ri.Memory=mem;
ri.Pos=0;
ri.Max=len;
fh=&ri;
Lesen(fh,&Buffer,12);
if(strncmp(&Buffer[0],"FORM",4)!=0)
{ InfoRequest("Bild hat kein IFF-Format!");
return(FALSE); }
if(strncmp(&Buffer[8],"ILBM",4)!=0)
{ InfoRequest("Bild hat kein ILBM-Format!");
return(FALSE); }
BMHDFlag=FALSE;
BODYFlag=FALSE;
CAMGFlag=FALSE;
CMAPFlag=FALSE;
CRNGFlag=FALSE;
Loop:
FoundChunk=FALSE;
l=Lesen(fh,&Buffer,8);
if((l==0)||((BMHDFlag==TRUE)&&(BODYFlag==TRUE)&&(CMAPFlag==TRUE)))
{
if((BMHDFlag==TRUE)&&(BODYFlag==TRUE)&&(CMAPFlag==TRUE))
{
ShowTitle(scr,FALSE);
if(CRNGFlag==TRUE)
{
if(crng.Active!=0)
{
y=crng.Rate/273;
if(y==0) y=1;
y=50/y;
while((MouseButton())==0)
{
Farbe.Red=Farben[crng.Low].Red;
Farbe.Green=Farben[crng.Low].Green;
Farbe.Blue=Farben[crng.Low].Blue;
for(i=crng.Low;i<crng.High;i++)
{
Farben[i].Red=Farben[i+1].Red;
Farben[i].Green=Farben[i+1].Green;
Farben[i].Blue=Farben[i+1].Blue;
}
Farben[crng.High].Red=Farbe.Red;
Farben[crng.High].Green=Farbe.Green;
Farben[crng.High].Blue=Farbe.Blue;
for(i=crng.Low;i<crng.High;i++)
{
SetRGB4(&scr->ViewPort,i,Farben[i].Red,
Farben[i].Green,
Farben[i].Blue);
}
Delay(y);
}
}
}
else
{
while((MouseButton())==0)
Delay(5);
}
CloseScreen(scr);
return(TRUE);
}
else
{
if((BMHDFlag==TRUE)||(BODYFlag==TRUE)||(CMAPFlag==TRUE))
{
if(BMHDFlag==FALSE) InfoRequest("Bild hat keinen BMHD-Chunk!");
else if(BODYFlag==FALSE) InfoRequest("Bild hat keinen BODY-Chunk!");
else if(CMAPFlag==FALSE) InfoRequest("Bild hat keinen CMAP-Chunk!");
if(scr!=NULL) CloseScreen(scr);
return(FALSE);
}
}
}
ChunkLen=Buffer[4]*16777216+Buffer[5]*65536+Buffer[6]*256+Buffer[7];
if(strncmp(&Buffer,"BMHD",4)==0)
{
if(sizeof(struct BMHD)<ChunkLen) InfoRequest("BMHD!");
Lesen(fh,&bmhd,ChunkLen);
if(bmhd.Compression>1)
{
InfoRequest("Unbekannte Kompressionsmethode!");
return(FALSE);
}
scrWidth=bmhd.ScreenWidth;
scrHeight=bmhd.ScreenHeight;
iDepth=bmhd.BitPlanes;
iWidth=bmhd.Width;
iHeight=bmhd.Height;
iRowBytes=iWidth/8;
scrRowBytes=scrWidth/8;
ns.LeftEdge = 0;
ns.TopEdge = 0;
ns.Width = scrWidth;
ns.Height = scrHeight;
ns.Depth = iDepth;
ns.DetailPen = 1;
ns.BlockPen = 0;
if(CAMGFlag==TRUE)
{
ns.ViewModes = camg.ViewModes;
}
else
{
ns.ViewModes = 0;
if(ns.Width>320) ns.ViewModes |= HIRES;
if(ns.Height>256) ns.ViewModes |= LACE;
}
ns.Type = CUSTOMSCREEN;
ns.Font = NULL;
ns.DefaultTitle = "Ende mit Mausklick";
ns.Gadgets = NULL;
ns.CustomBitMap = NULL;
scr=OpenScreen(&ns);
if(scr==NULL)
{
InfoRequest("Kann Screen nicht öffnen!");
return(FALSE);
}
BMHDFlag=TRUE;
FoundChunk=TRUE;
}
if(strncmp(&Buffer,"CMAP",4)==0)
{
if(BMHDFlag==FALSE)
{ InfoRequest("BMHD-Chunk muß vor CMAP-Chunk stehen!");
return(FALSE); }
AnzFarben=ColorCount[bmhd.BitPlanes];
for(i=0;i<AnzFarben;i++)
{
if(ChunkLen>=3)
{
Lesen(fh,&Farbe,3);
ChunkLen-=3;
}
else
{
Farbe.Red=0;
Farbe.Green=0;
Farbe.Blue=0;
}
Farben[i].Red=Farbe.Red>>4;
Farben[i].Green=Farbe.Green>>4;
Farben[i].Blue=Farbe.Blue>>4;
SetRGB4(&scr->ViewPort,i,Farben[i].Red,
Farben[i].Green,
Farben[i].Blue);
}
CMAPFlag = TRUE;
FoundChunk = TRUE;
}
if(strncmp(&Buffer,"BODY",4)==0)
{
if(BMHDFlag==FALSE)
{ InfoRequest("BMHD-Chunk muß vor BODY-Chunk stehen!");
return(FALSE); }
if(bmhd.Compression==0)
{
for(y=0;y<iHeight;y++)
{
for(b=0;b<iDepth;b++)
{
dest=(ULONG)(scr->RastPort.BitMap->Planes[b])+(ULONG)y*(ULONG)scrRowBytes;
Lesen(fh,dest,iRowBytes);
}
}
}
else
{
for(y=0;y<iHeight;y++)
{
for(b=0;b<iDepth;b++)
{
dest=(ULONG)(scr->RastPort.BitMap->Planes[b])+(ULONG)y*(ULONG)scrRowBytes;
ByteCount=0;
while(ByteCount<iRowBytes)
{
Lesen(fh,&Buffer[0],1);
if(Buffer[0]<128)
{
Lesen(fh,(ULONG)dest+(ULONG)ByteCount,Buffer[0]+1);
ByteCount+=Buffer[0]+1;
}
else if(Buffer[0]>128)
{
Lesen(fh,&Buffer[1],1);
for(i=ByteCount;i<=(ByteCount+(257-Buffer[0]));i++)
{ *((UBYTE *)dest+(UBYTE *)i)=Buffer[1]; }
ByteCount += 257-Buffer[0];
}
}
}
}
}
BODYFlag = TRUE;
FoundChunk = TRUE;
}
if(strncmp(&Buffer,"CAMG",4)==0)
{
Lesen(fh,&camg,ChunkLen);
if(BMHDFlag==FALSE)
{ InfoRequest("BMHD-Chunk muß vor CAMG-Chunk stehen!");
return(FALSE); }
scr->ViewPort.Modes=camg.ViewModes;
RemakeDisplay();
CAMGFlag = TRUE;
FoundChunk = TRUE;
}
if(strncmp(&Buffer,"CRNG",4)==0)
{
if(CRNGFlag==FALSE)
{
Lesen(fh,&crng,ChunkLen);
CRNGFlag = TRUE;
FoundChunk = TRUE;
}
}
if(FoundChunk==FALSE)
{
Jump(fh,ChunkLen);
if((ChunkLen & 1)) Jump(fh,1);
}
goto Loop;
}
/* IFF-Bild laden und anzeigen */
BOOL ShowPicture(name)
UBYTE *name;
{
REGISTER UBYTE *mem;
REGISTER ULONG size;
register struct FileHandle *fh;
fh=Open(name,MODE_OLDFILE);
if(fh!=NULL)
{
Seek(fh,0,OFFSET_END);
size=Seek(fh,0,OFFSET_BEGINNING);
mem=AllocMem(size,MEMF_CLEAR|MEMF_PUBLIC);
if(mem!=NULL)
{
Read(fh,mem,size);
DisplayPicture(mem,size);
FreeMem(mem,size);
}
else ErrorRequest(ERROR_ALLOC);
}
else return(FALSE);
return(TRUE);
}
/* Testen, ob Maustaste gedrückt ist */
#asm
public _MouseButton
_MouseButton:
btst #6,$bfe001
bne 1$
move.l #1,d0
rts
1$:
clr.l d0
rts
#endasm
/* Online-Hilfe aufrufen */
VOID Help(name,seite)
UBYTE *name;
UWORD seite;
{
REGISTER BOOL bool;
UBYTE str[130];
sprintf(&str,"run >NIL: cc:prgs/atkey/hlp %s %ld",name,seite);
bool=Execute(&str,0L,0L);
if(bool==FALSE)
{
MultiRequest("Kann Hilfe-System nicht starten:",
"AT:Online Help","Okay",NULL);
}
}
UWORD BorderHeight()
{
register struct Screen *scr;
scr=OpenWorkBench();
return(scr->WBorTop+scr->Font->ta_YSize+1);
}